{%mainunit bitcoin_p2p.pas}

{$IFDEF INTERFACE}
type
  { TTxIn is part of a Tx message. It points to an output from where to spend
    the coins. The Tx message contains a list of these. In the wiki they have
    split it into OutPoint and TxIn but I have it in one class for simplicity.
    This is not a stand-alone protocol message but it has the same Parse and
    Serialize mechanism as messages so its derived from the same base class }
  TTxIn = class(TMsg)
    OutHash         : TSHA256Digest;  // from which tx to take the coins...
    OutIndex        : DWord;          // ...and which of its outputs exactly
    SignatureScript : String;
    Sequence        : DWord;  // (version # for updating still unconfirmed tx)
    procedure ParseAndProcess; override;
    procedure SerializeToStream(AStream: TStringStream);
  end;

{$ENDIF}
{$IFDEF IMPLEMENTATION}

procedure TTxIn.ParseAndProcess;
begin
  ReadBuffer(OutHash[1], Length(OutHash));
  OutIndex := ReadDWord;
  SignatureScript := ReadVarStr;
  Sequence := ReadDWord;
end;

procedure TTxIn.SerializeToStream(AStream: TStringStream);
begin
  FSendData := AStream;
  WriteBuffer(OutHash[1], Length(OutHash));
  WriteDWord(OutIndex);
  WriteVarStr(SignatureScript);
  WriteDWord(Sequence);
end;

{$ENDIF}
